<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta charset="utf-8">
    <title>ExcelTest</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/webjars/layui/2.4.5/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>

<body>
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>测试Excel上传操作</legend>
    </fieldset>
    <div class="layui-main">
        <div class="layui-upload ">
            <button type="button" class="layui-btn layui-btn-normal" id="check">选择文件</button>
            <button type="button" class="layui-btn" id="begin">开始上传</button>
        </div>
    </div>
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>测试Excel下载操作</legend>
    </fieldset>
    <div class="layui-main">
        <a href="http://localhost:8080/downXlsx" class="layui-btn">下载所有数据库数据</a></div>
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>测试数据库数据浏览</legend>
    </fieldset>
    <div class="layui-main">
        <a href="http://localhost:8080/showList" class="layui-btn">浏览所有数据库数据</a></div>
    <script src="/webjars/layui/2.4.5/layui.js" charset="utf-8"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
    <script>
        layui.use('upload', function () {
            var $ = layui.jquery
                , upload = layui.upload;
            debugger;
            //选完文件后不自动上传
            upload.render({
                elem: '#check'
                , accept: 'file' //普通文件
                , url: 'http://localhost:8080/importUser'
                , auto: false
                , multiple: true
                , bindAction: '#begin'
                , before: function (request) {
                    index = layer.msg('文档上传中', {
                        icon: 16
                        , shade: 0.01
                        , time: 0//不自动关闭
                    });
                }
                , done: function (res) {
                    layer.close(index);
                    //如果上传失败
                    if (res.error != null) {
                        layer.msg("上传失败");
                    } else {
                        layer.close(index);
                        layer.msg("上传成功");
                    }
                }
                , error: function () {
                    layer.close(index);
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        upload.upload();
                    });
                }
            });
        });



    </script>

</body>

</html>